
<#include "/common/head.html"/>

<table id="dg"></table>
<div id="tb" style="padding: 2px 5px;">
	<div class="wrap_search">
		<span class="search_item" style="width: 100%"> <span class="item_text">合同分类: </span> <span
			class="item_obj" style="width: 220px;"> <input class="easyui-combobox" name="ec_type"
				id="ec_type" value="" style="width: 200px"
				data-options="valueField: 'id',
					textField: 'text',
					data: [{id:'', text:''}<#list classify.keySet() as key>,{id:'${key}', 
					text:'${classify.get(key)}'}</#list>]" />
		</span>
		</span>
	</div>

	<div class="dg_btns_wrap">
		<a href="javascript:void(0)" class="easyui-linkbutton addBtn" iconCls="glyphicon-plus"
			plain="true" onclick="add()">上传</a>
		<a href="javascript:void(0)" class="easyui-linkbutton delBtn" iconCls="glyphicon-remove"
			plain="true" onclick="del()">删除</a>
		<div id="searchBtnWrap" style="float: right; padding-right: 40px;">
			<a href="javascript:void(0)" class="easyui-linkbutton color1" iconCls="glyphicon-search"
				onclick="zcurdSearch(this)">搜索</a>
			<a href="javascript:void(0)" class="easyui-linkbutton color2" iconCls="glyphicon-repeat"
				onclick="flushPage()">重置</a>
		</div>
	</div>
</div>


<script type="text/javascript">
	var datagrid = $("#dg");

	var dgOptions = {
		rownumbers : true,
		fit : true,
		border : false,
		rownumbers : true,
		url : 'listData',
		method : 'post',
		toolbar : '#tb',
		pageSize : 20,
		pagination : true,
		multiSort : true,
		sortName : getInitParam().sort,
		sortOrder : getInitParam().order,
		queryParams : getInitParam(),

		columns : [ [ {
			field : 'id',
			checkbox : true
		}, {
			field : 'name',
			title : '合同名称',
			sortable : true
		}, {
			field : 'ec_type',
			title : '合同分类',
			sortable : true
		}, {
			field : 'type',
			title : '文件类型',
			sortable : true
		}, {
			field : 'operate',
			title : '操作',
			width : 140,
			frozen : true,
			formatter : function(value, row, index) {
				var html = '<a class="operate" href="downloadFile?id=' + row.id + '">下载</a>';
				return html;
			}
		} ] ],
		loadFilter : function(data) {
			if (data.result && data.result == 'fail') { //失败时，错误消息提示
				showWarnMsg(data.msg);
				return {};
			} else {
				return data;
			}
		}
	};
	$(function() {
		handleAuthDataRule();
		datagrid.datagrid(dgOptions);
	});

	function zcurdSearch() {
		var param = zcurdGetParam();
		datagrid.datagrid("load", {
			queryParams : param
		})
	}

	function zcurdGetParam() {
		var param = {};
		$("#tb :input[name]").each(function(i, item) {
			if ($(item).val()) {
				param[$(item).attr("name")] = $(item).val();
			}
		});
		return param;
	}

	function getInitParam() {
		var param = {};
		$("#tb :input[name]").each(function(i, item) {
			if ($(item).val()) {
				param["queryParams[" + $(item).attr("name") + "]"] = $(item).val();
			}
		});
		if ("") {
			param.sort = "";
			param.order = "asc";
		}
		return param;
	}

	var initPara = zcurdGetParam();
	function add() {
		top.window.subPage.loadCurrDatagrid = function() {
			showMsg("增加成功！");
			datagrid.datagrid("load");
		}
		top.openWindow("合同管理-增加", getCurrUrl("addPage") + "?" + $.param(initPara), {
			size : '600x400'
		});
	}

	function del() {
		var ids = [];
		$.each(datagrid.datagrid("getSelections"), function(i, item) {
			ids.push(item.id);
		});
		if (ids.length < 1) {
			showWarnMsg("请选择需要删除的数据！");
			return;
		}
		confirmMsg("确认删除？", function() {
			$.post("delete", {
				id : ids
			}, function(data) {
				showMsg("删除成功！");
				datagrid.datagrid("reload");
			});
		});
	}

	/**
	 * 打开子页
	 */
	var _openSubPageFlag = false;
	function _openSubPage(pageUrl) {
		if (!_openSubPageFlag) {
			$("#subLayout").layout("expand", "east");
			setTimeout(function() {
				$("#subIframe").attr("src", pageUrl);
			}, 600);
			_openSubPageFlag = true;
		} else {
			$("#subIframe").attr("src", pageUrl);
		}
	}

	//扩展js
</script>

<#include "/common/dialogWindow.html"/>
<#include "/common/foot.html"/>
